<?php

namespace App\Models\Refund;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CustomRefundBankuan extends Model
{
    protected $table = 'custom_refund_approve_bankuan';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];
    /**
     * 列表
     */
    public static function getList($request, $memberinfo, $isgetall)
    {
        $cpid = $memberinfo['cpid'] ?? 0;
        $query = self::orderBy('create_at', 'desc')
            ->where('cpid', '=', $cpid);
        $main_id = $request->id ?? 0;
        if($main_id){
            $query->where('main_id', '=', $main_id);
        }
        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();
            return ['list' => $list];
        }
    }
    public function customRefund(){
        return $this->belongsTo(CustomRefund::class, 'id', 'main_id');
    }
}
